package xin.printk.android.module.login;

import xin.printk.android.BasicApplication;
import xin.printk.android.R;
import xin.printk.android.utils.RequestCallback;

public class LoginPresenter implements LoginContract.Presenter {

    private LoginContract.View mLoginView;
    private LoginModel mLoginModel;

    public LoginPresenter(LoginContract.View view) {
        mLoginView = view;
        mLoginModel = new LoginModel();
    }

    @Override
    public void login() {
        if (mLoginView.getAccount().isEmpty()) {
            mLoginView.showMessage(BasicApplication.getContext().getString(R.string.account_null_tips));
            return;
        }
        if (mLoginView.getPassword().isEmpty()) {
            mLoginView.showMessage(BasicApplication.getContext().getString(R.string.password_null_tips));
            return;
        }
        mLoginModel.login(mLoginView.getAccount(), mLoginView.getPassword(), new RequestCallback() {
            @Override
            public <T> void onSuccess(T t) {
                mLoginView.loginSuccess();
            }

            @Override
            public void onFailure(String message) {
                mLoginView.showMessage(message);
            }
        });
    }
}
